import { Dispatch  } from 'redux'
import * as actionTypes from '../constants'
import {
    getRankingPartitionsRequest,
    getRankingRequest,
    getPartitionRequest
} from '@/api/request'

// 页面级别action   
// Promise.all 
export const getHomeDataAction = (rId:string) => {
    return (dispatch:Dispatch) => {
        dispatch(setLoading(true))
        return Promise.all([
            getPartitionRequest(),
            getRankingPartitionsRequest(),
            getRankingRequest(rId)
        ]).then(([partitionsResult,rankingpartitionsResult,videoResult]) => {
            // console.log(partitionsResult,'////')
            const partitions = partitionsResult.data[0];
            partitions.filter((partitions:any) => 
            [13,23,11,177].indexOf(partitions.id) === -1)
            dispatch(setOneLevelPartitions(partitions))
            // console.log(rankingpartitionsResult,videoResult,'----------')
            dispatch(setRankingPartitions(rankingpartitionsResult.data))
            dispatch(setRankingVideos(videoResult.data.list))
            dispatch(setLoading(false))
        })
    }
}  

export const setOneLevelPartitions = (data:any[]) => ({
    type:actionTypes.SET_ONE_LEVEL_PARTITIONS,
    data
})
export const setLoading = (data:boolean) =>({
    type:actionTypes.SET_LOADING,
    data
})
export const setRankingPartitions = (data:any[]) =>({
    type:actionTypes.SET_RANKING_PARTITIONS,
    data
})
export const setRankingVideos = (data:any[]) =>({
    type:actionTypes.SET_RANKING_VIDEOS,
    data
})